var a = [];
for (let i = 0; i < 10; i++) {
  a[i] = function () {
    console.log(i);
  };
}
a[6](); // 6

let [foo, bar, [bat,baw]]=[1,2,[9,8]];
foo
bar
bat
baw
console.log(foo);
console.log(bat);

let {length:len} = 'waht are u doing?!!!';
console.log(len);

//函数参数的解构
function add ([x,y]) {
	alert(x+y);
}
add([3,4]);

//includes(),startsWith().endsWith()
var s = 'HEI!MAN!';


if (!s.endsWith('!',7)) {
 alert(s.includes('e',2))
}
else{
	console.log(s.startsWith('HEI'));
}

//模板字符串
var name = 'Jessica';
$("#try").append(`
	<p>yes,IS you!</p>
	<p>no,that you!</p>
	<span>${name}</span>`);

var np = 'JE';
function moduleHtml (argument) {
	var strhtml = `
	<p>yes,IS you!</p>
	<p>no,that you!</p>
	<span>${np}</span>`;5

	$("#try").append(strhtml);
}
moduleHtml();

//数组
let shuzu = Array.of(3,11,8);
console.log(shuzu.length);

$("#test").click(function  () {
	  let poor =  Array.of(2,4,6,7.8,-1,0);
      console.log(poor.find((n) => n > 0));
	alert([1, 4, -5, 10].find((n) => n < 0));
})

//函数
//ES6允许为函数的参数设置默认值，即直接写在参数定义的后面。
function log(x, y = 'World') {
  console.log(x, y);
}

log('Hello') // Hello World
log('Hello', 'China') // Hello China
log('Hello', '') // Hello

//与解构赋值一起用
function foor({x, y = 5}) {
  console.log(x, y);
}

foor({}) // undefined, 5
foor({x: 1}) // 1, 5
foor({x: 1, y: 2}) // 1, 2
//foor() // TypeError: Cannot read property 'x' of undefined

var w = 1;

function f1(w, z = w) {
  console.log(z);
}

f1(2)

let h = 1;

function f2(r = h) {
  let h = 2;
  console.log(r);
}

f2()

//rest参数（形式为"...变量名"），函数的length属性，不包括rest参数。
function add(...values) {
  let sum = 0;

  for (var val of values) {
    sum += val;
  }

  return sum;
}
console.log(add(2, 5, 3));

// arguments变量的写法
//const sortNumbers = () =>
  //Array.prototype.slice.call(arguments).sort();

// rest参数的写法
const sortNumbers = (...numbers) => numbers.sort();

//拓展运算符
function push(array, ...items) {
  array.push(...items);
}

function add(m, n) {
  return m + n;
}

var numbers = [4, 38];
console.log(add(...numbers)); 

var arr1 = [0, 1, 2];
var arr2 = [3, 4, 5];
alert(arr1.push(...arr2));

//箭头函数
var num1 = 3;
var num2 = 4;
var num = (num1,num2) => num1 + num2;

var handler = {
  id: "123456",

  init: function() {
    document.addEventListener("click",
      event => this.doSomething(event.type), false);
  },

  doSomething: function(type) {
    console.log("Handling " + type  + " for " + this.id);
  }
};


//属性的简洁表示

var baz = {foo:foo}//ES6允许直接写入变量和函数，作为对象的属性和方法

function g (c,d) {
	return{c,d};//=return{c:c,d:d}
}

var me = {
	method() {
		return 'return';
	}
} ; //简写方法

//模块输出变量
var ms = {};

function getItem (key) {
  return key in ms ? ms[key] : null;
}

function setItem (key, value) {
  ms[key] = value;
}

function clear () {
  ms = {};
}

//class 类
class Point {
     construstor(j,k) {
     	this.j = j;
     	this.k = k;
     }

     toString() {
     	return '('+ this.j + ',' + this.k + ')';
     }
}

require('babel!./m.js')

/*
//模块MODULE*/
import {firstName,lastName,ageNum} from './m.js';





// import { stat, exists, readFile } from 'fs.js';

console.log(firstName,lastName,ageNum);